package com.ruoyi.workflow.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.workflow.mapper.BusStoreInfoMapper;
import com.ruoyi.workflow.domain.BusStoreInfo;
import com.ruoyi.workflow.service.IBusStoreInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 门店管理Service业务层处理
 *
 * @author lhl
 * @date 2022-11-24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusStoreInfoServiceImpl extends ServiceImpl<BusStoreInfoMapper, BusStoreInfo> implements IBusStoreInfoService {
@Autowired
private BusStoreInfoMapper mapper;
@Autowired
private ISysUserService userService;
    /**
     * 查询门店管理列表
     *
     * @param busStoreInfo 门店管理
     * @return 门店管理
     */
    @Override
    public List<BusStoreInfo> selectBusStoreInfoList(BusStoreInfo busStoreInfo) {
        return getBaseMapper().selectBusStoreInfoList(busStoreInfo);
    }

    @Override
    public void deleteBatchByIds(List<Long> asList) {

    }

    @Override
    public void updateStatus(List<Long> asList) {
          mapper.updateStatus(asList);
    }

    @Override
    public boolean save(BusStoreInfo entity) {
        if (entity.getStatus()==2) {
            throw new ServiceException("新增更新时不允许更该状态为删除");
        }
        Long managerId = entity.getManagerId();
        entity.setCreatedTime(new Date());
        System.out.println(entity.getCreatedTime());
        SysUser sysUser = userService.selectUserById(managerId);
        entity.setCreatorId(sysUser.getUserId());
        entity.setManagerTel(sysUser.getPhonenumber());
        entity.setManagerName(sysUser.getUserName());
        boolean save = super.save(entity);
        return save;
    }

    @Override
    public boolean updateById(BusStoreInfo entity) {
        if (entity.getStatus()==2) {
            throw new ServiceException("新增更新时不允许更该状态为删除");
        }
        entity.setUpdatedTime(new Date());
        SysUser sysUser = userService.selectUserById(entity.getManagerId());
        entity.setManagerTel(sysUser.getPhonenumber());
        entity.setManagerName(sysUser.getUserName());
        entity.setUpdatorId(sysUser.getUserId());
        entity.setUpdatedTime(new Date());
        return super.updateById(entity);
    }

}
